import type { CategoryForm, CategoryQuery, CategoryVO } from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询分类列表
 * @param params
 * @returns 分类列表
 */
export function categoryList(params?: CategoryQuery) {
  return requestClient.get<PageResult<CategoryVO>>('/category/category/list', {
    params,
  });
}

export function categoryNodeList(params?: CategoryQuery) {
  return requestClient.get<PageResult<CategoryVO[]>>(
    '/category/category/node/list',
    { params },
  );
}

export function categoryNodeTree(params?: CategoryQuery) {
  return requestClient.get<CategoryVO[]>('/category/category/node/list', {
    params,
  });
}

/**
 * 导出分类列表
 * @param params
 * @returns 分类列表
 */
export function categoryExport(params?: CategoryQuery) {
  return commonExport('/category/category/export', params ?? {});
}

/**
 * 查询分类详情
 * @param id id
 * @returns 分类详情
 */
export function categoryInfo(id: ID) {
  return requestClient.get<CategoryVO>(`/category/category/${id}`);
}

/**
 * 新增分类
 * @param data
 * @returns void
 */
export function categoryAdd(data: CategoryForm) {
  return requestClient.postWithMsg<void>('/category/category', data);
}

/**
 * 更新分类
 * @param data
 * @returns void
 */
export function categoryUpdate(data: CategoryForm) {
  return requestClient.putWithMsg<void>('/category/category', data);
}

/**
 * 删除分类
 * @param id id
 * @returns void
 */
export function categoryRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/category/category/${id}`);
}
